from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-05-22 14:02:29.714798
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sun, 22, May, 2022
Time: 14:02:36
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.3738
Nobs: 664.000 HQIC: -49.7473
Log likelihood: 8204.96 FPE: 1.96079e-22
AIC: -49.9835 Det(Omega_mle): 1.71398e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.311632 0.060283 5.170 0.000
L1.Burgenland 0.106696 0.038765 2.752 0.006
L1.Kärnten -0.109711 0.020349 -5.391 0.000
L1.Niederösterreich 0.199893 0.080675 2.478 0.013
L1.Oberösterreich 0.124682 0.079845 1.562 0.118
L1.Salzburg 0.256778 0.041213 6.230 0.000
L1.Steiermark 0.043539 0.054039 0.806 0.420
L1.Tirol 0.102411 0.043514 2.353 0.019
L1.Vorarlberg -0.063606 0.038613 -1.647 0.100
L1.Wien 0.032690 0.070650 0.463 0.644
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.045190 0.128329 0.352 0.725
L1.Burgenland -0.031314 0.082522 -0.379 0.704
L1.Kärnten 0.040587 0.043319 0.937 0.349
L1.Niederösterreich -0.182842 0.171739 -1.065 0.287
L1.Oberösterreich 0.448946 0.169973 2.641 0.008
L1.Salzburg 0.284849 0.087734 3.247 0.001
L1.Steiermark 0.107175 0.115037 0.932 0.352
L1.Tirol 0.311466 0.092633 3.362 0.001
L1.Vorarlberg 0.021638 0.082199 0.263 0.792
L1.Wien -0.037801 0.150398 -0.251 0.802
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.184450 0.030942 5.961 0.000
L1.Burgenland 0.090207 0.019897 4.534 0.000
L1.Kärnten -0.007612 0.010445 -0.729 0.466
L1.Niederösterreich 0.256252 0.041409 6.188 0.000
L1.Oberösterreich 0.156262 0.040983 3.813 0.000
L1.Salzburg 0.042461 0.021154 2.007 0.045
L1.Steiermark 0.024217 0.027737 0.873 0.383
L1.Tirol 0.083931 0.022335 3.758 0.000
L1.Vorarlberg 0.053172 0.019819 2.683 0.007
L1.Wien 0.117701 0.036263 3.246 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.109085 0.030984 3.521 0.000
L1.Burgenland 0.046081 0.019924 2.313 0.021
L1.Kärnten -0.014134 0.010459 -1.351 0.177
L1.Niederösterreich 0.185001 0.041464 4.462 0.000
L1.Oberösterreich 0.327597 0.041038 7.983 0.000
L1.Salzburg 0.101778 0.021182 4.805 0.000
L1.Steiermark 0.109321 0.027774 3.936 0.000
L1.Tirol 0.096636 0.022365 4.321 0.000
L1.Vorarlberg 0.059535 0.019846 3.000 0.003
L1.Wien -0.021899 0.036312 -0.603 0.546
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.112882 0.057643 1.958 0.050
L1.Burgenland -0.043472 0.037067 -1.173 0.241
L1.Kärnten -0.046176 0.019458 -2.373 0.018
L1.Niederösterreich 0.141503 0.077142 1.834 0.067
L1.Oberösterreich 0.162454 0.076349 2.128 0.033
L1.Salzburg 0.281426 0.039409 7.141 0.000
L1.Steiermark 0.055730 0.051673 1.079 0.281
L1.Tirol 0.164280 0.041609 3.948 0.000
L1.Vorarlberg 0.095772 0.036922 2.594 0.009
L1.Wien 0.077726 0.067556 1.151 0.250
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.060200 0.045490 1.323 0.186
L1.Burgenland 0.031647 0.029252 1.082 0.279
L1.Kärnten 0.051178 0.015355 3.333 0.001
L1.Niederösterreich 0.207680 0.060877 3.411 0.001
L1.Oberösterreich 0.317701 0.060252 5.273 0.000
L1.Salzburg 0.041474 0.031100 1.334 0.182
L1.Steiermark 0.007174 0.040778 0.176 0.860
L1.Tirol 0.132447 0.032836 4.034 0.000
L1.Vorarlberg 0.065223 0.029137 2.238 0.025
L1.Wien 0.086049 0.053312 1.614 0.107
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.166658 0.054616 3.051 0.002
L1.Burgenland 0.007058 0.035121 0.201 0.841
L1.Kärnten -0.065405 0.018436 -3.548 0.000
L1.Niederösterreich -0.094048 0.073091 -1.287 0.198
L1.Oberösterreich 0.204271 0.072340 2.824 0.005
L1.Salzburg 0.054215 0.037339 1.452 0.147
L1.Steiermark 0.241576 0.048959 4.934 0.000
L1.Tirol 0.502304 0.039424 12.741 0.000
L1.Vorarlberg 0.057891 0.034983 1.655 0.098
L1.Wien -0.072328 0.064008 -1.130 0.258
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.147477 0.060537 2.436 0.015
L1.Burgenland 0.003849 0.038928 0.099 0.921
L1.Kärnten 0.059991 0.020435 2.936 0.003
L1.Niederösterreich 0.180450 0.081015 2.227 0.026
L1.Oberösterreich -0.054586 0.080182 -0.681 0.496
L1.Salzburg 0.206404 0.041387 4.987 0.000
L1.Steiermark 0.134717 0.054267 2.482 0.013
L1.Tirol 0.070543 0.043698 1.614 0.106
L1.Vorarlberg 0.143186 0.038776 3.693 0.000
L1.Wien 0.109666 0.070948 1.546 0.122
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.373511 0.035706 10.461 0.000
L1.Burgenland -0.000180 0.022960 -0.008 0.994
L1.Kärnten -0.021653 0.012053 -1.797 0.072
L1.Niederösterreich 0.216923 0.047784 4.540 0.000
L1.Oberösterreich 0.228295 0.047293 4.827 0.000
L1.Salzburg 0.039107 0.024411 1.602 0.109
L1.Steiermark -0.015706 0.032007 -0.491 0.624
L1.Tirol 0.093398 0.025774 3.624 0.000
L1.Vorarlberg 0.053843 0.022870 2.354 0.019
L1.Wien 0.034208 0.041846 0.817 0.414
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.037607 0.119901 0.175150 0.144180 0.101447 0.087975 0.041598 0.212568
Kärnten 0.037607 1.000000 -0.018623 0.135244 0.052744 0.090421 0.440513 -0.060064 0.094192
Niederösterreich 0.119901 -0.018623 1.000000 0.324155 0.130412 0.283552 0.076994 0.162745 0.301033
Oberösterreich 0.175150 0.135244 0.324155 1.000000 0.220351 0.309242 0.168399 0.151706 0.252028
Salzburg 0.144180 0.052744 0.130412 0.220351 1.000000 0.129350 0.099215 0.114857 0.130683
Steiermark 0.101447 0.090421 0.283552 0.309242 0.129350 1.000000 0.138951 0.119676 0.051447
Tirol 0.087975 0.440513 0.076994 0.168399 0.099215 0.138951 1.000000 0.070129 0.148358
Vorarlberg 0.041598 -0.060064 0.162745 0.151706 0.114857 0.119676 0.070129 1.000000 0.008466
Wien 0.212568 0.094192 0.301033 0.252028 0.130683 0.051447 0.148358 0.008466 1.000000